package src;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.Vector;

import org.apache.lucene.search.Searcher;

public class Debug {

	public static void print(String s){
		//System.out.println(s);
	}
	public static void print(int i){
		//System.out.println(i);
	}
	
	public static void printMatrix (Vector matrix) 
	throws UnsupportedEncodingException{
		for(int i=0;i< matrix.size(); i++){
			Vector vec = (Vector)matrix.get(i);
			Variation var = (Variation)vec.get(0);
			System.out.println(var.token);
			System.out.println("==============");
			for(int j=0;j< vec.size(); j++){
				var = (Variation)vec.get(j);
				Debug.printUTF(var.word+"  : "+var.weight);
			}
			System.out.println("------------------------------");
		}
	}
	
	public static void printVector(Vector<Variation> v){
		for(int i=0; i< v.size(); i++){
			Variation vv = v.get(i);
			System.out.println(vv.word);
		}
	}
	public static void printUTF(String s){
		try {
			PrintStream sysout = new PrintStream(System.out, true, "UTF-8");
			sysout.print(s);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}
	
	public static void printIds(Vector allDocs){
		if(allDocs != null){
			for(int i=0; i< allDocs.size(); i++){
				MyDoc md = (MyDoc)allDocs.get(i);
				System.out.print(md.hitId+" ");
			}
			System.out.println();
		}
	}
	
	public static void printResult
	(String query, Vector doclist, double executionTime,String resultFile){
		File file = new File(resultFile);
		try {
			BufferedWriter writer = new BufferedWriter(
					new FileWriter(file, true));
			int size = doclist.size();
			writer.write(query);
			writer.newLine();
			writer.write(Integer.toString(size));
			writer.newLine();
			QApair qap = null;
			for(int i=0;i<Math.min(doclist.size(), 5);i++){
				qap = (QApair)doclist.get(i);
				//System.out.println(qap.score);
				writer.write(qap.quest);
				writer.newLine();
			}
			writer.write(Double.toString(executionTime));
			writer.newLine();
			writer.newLine();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}		
	}

	public static void printHitId(Vector hitIds, Searcher searcher){
		if(hitIds != null){
			for(int i=0; i< hitIds.size(); i++){
				Integer in = (Integer)hitIds.get(i);
				//Document doc = searcher.doc(in.)
			}
		}
		else{
			System.out.println("null doc");
		}
	}
}
